<?

global $_MYSQL_ERROR;

$_MYSQL_ERROR = array (
	1022=>array('ER_DUP_KEY ','S1000 ','23000'),
	1037=>array('ER_OUTOFMEMORY ','S1001 ','HY001'),
	1038=>array('ER_OUT_OF_SORTMEMORY ','S1001 ','HY001'),
	1040=>array('ER_CON_COUNT_ERROR ','08004 ','08004'),
	1042=>array('ER_BAD_HOST_ERROR ','08004 ','08S01'),
	1043=>array('ER_HANDSHAKE_ERROR ','08004 ','08S01'),
	1044=>array('ER_DBACCESS_DENIED_ERROR ','S1000 ','42000'),
	1045=>array('ER_ACCESS_DENIED_ERROR ','28000 ','28000'),
	1047=>array('ER_UNKNOWN_COM_ERROR ','08S01 ','HY000'),
	1050=>array('ER_TABLE_EXISTS_ERROR ','S1000 ','42S01'),
	1051=>array('ER_BAD_TABLE_ERROR ','42S02 ','42S02'),
	1052=>array('ER_NON_UNIQ_ERROR ','S1000 ','23000'),
	1053=>array('ER_SERVER_SHUTDOWN ','S1000 ','08S01'),
	1054=>array('ER_BAD_FIELD_ERROR ','S0022 ','42S22'),
	1055=>array('ER_WRONG_FIELD_WITH_GROUP ','S1009 ','42000'),
	1056=>array('ER_WRONG_GROUP_FIELD ','S1009 ','42000'),
	1057=>array('ER_WRONG_SUM_SELECT ','S1009 ','42000'),
	1058=>array('ER_WRONG_VALUE_COUNT ','21S01 ','21S01'),
	1059=>array('ER_TOO_LONG_IDENT ','S1009 ','42000'),
	1060=>array('ER_DUP_FIELDNAME ','S1009 ','42S21'),
	1061=>array('ER_DUP_KEYNAME ','S1009 ','42000'),
	1062=>array('ER_DUP_ENTRY ','S1009 ','23000'),
	1063=>array('ER_WRONG_FIELD_SPEC ','S1009 ','42000'),
	1064=>array('ER_PARSE_ERROR ','42000 ','42000'),
	1065=>array('ER_EMPTY_QUERY ','42000 ','42000'),
	1066=>array('ER_NONUNIQ_TABLE ','S1009 ','42000'),
	1067=>array('ER_INVALID_DEFAULT ','S1009 ','42000'),
	1068=>array('ER_MULTIPLE_PRI_KEY ','S1009 ','42000'),
	1069=>array('ER_TOO_MANY_KEYS ','S1009 ','42000'),
	1070=>array('ER_TOO_MANY_KEY_PARTS ','S1009 ','42000'),
	1071=>array('ER_TOO_LONG_KEY ','S1009 ','42000'),
	1072=>array('ER_KEY_COLUMN_DOES_NOT_EXITS ','S1009 ','42000'),
	1073=>array('ER_BLOB_USED_AS_KEY ','S1009 ','42000'),
	1074=>array('ER_TOO_BIG_FIELDLENGTH ','S1009 ','42000'),
	1075=>array('ER_WRONG_AUTO_KEY ','S1009 ','42000'),
	1080=>array('ER_FORCING_CLOSE ','S1000 ','08S01'),
	1081=>array('ER_IPSOCK_ERROR ','08S01 ','08S01'),
	1082=>array('ER_NO_SUCH_INDEX ','S1009 ','42S12'),
	1083=>array('ER_WRONG_FIELD_TERMINATORS ','S1009 ','42000'),
	1084=>array('ER_BLOBS_AND_NO_TERMINATED ','S1009 ','42000'),
	1090=>array('ER_CANT_REMOVE_ALL_FIELDS ','S1000 ','42000'),
	1091=>array('ER_CANT_DROP_FIELD_OR_KEY ','S1000 ','42000'),
	1101=>array('ER_BLOB_CANT_HAVE_DEFAULT ','S1000 ','42000'),
	1102=>array('ER_WRONG_DB_NAME ','S1000 ','42000'),
	1103=>array('ER_WRONG_TABLE_NAME ','S1000 ','42000'),
	1104=>array('ER_TOO_BIG_SELECT ','S1000 ','42000'),
	1106=>array('ER_UNKNOWN_PROCEDURE ','S1000 ','42000'),
	1107=>array('ER_WRONG_PARAMCOUNT_TO_PROCEDURE ','S1000 ','42000'),
	1109=>array('ER_UNKNOWN_TABLE ','S1000 ','42S02'),
	1110=>array('ER_FIELD_SPECIFIED_TWICE ','S1000 ','42000'),
	1112=>array('ER_UNSUPPORTED_EXTENSION ','S1000 ','42000'),
	1113=>array('ER_TABLE_MUST_HAVE_COLUMNS ','S1000 ','42000'),
	1115=>array('ER_UNKNOWN_CHARACTER_SET ','S1000 ','42000'),
	1118=>array('ER_TOO_BIG_ROWSIZE ','S1000 ','42000'),
	1120=>array('ER_WRONG_OUTER_JOIN ','S1000 ','42000'),
	1121=>array('ER_NULL_COLUMN_IN_INDEX ','S1000 ','42000'),
	1129=>array('ER_HOST_IS_BLOCKED ','08004 ','HY000'),
	1130=>array('ER_HOST_NOT_PRIVILEGED ','08004 ','HY000'),
	1131=>array('ER_PASSWORD_ANONYMOUS_USER ','S1000 ','42000'),
	1132=>array('ER_PASSWORD_NOT_ALLOWED ','S1000 ','42000'),
	1133=>array('ER_PASSWORD_NO_MATCH ','S1000 ','42000'),
	1136=>array('ER_WRONG_VALUE_COUNT_ON_ROW ','S1000 ','21S01'),
	1138=>array('ER_INVALID_USE_OF_NULL ','S1000 ','42000'),
	1139=>array('ER_REGEXP_ERROR ','S1000 ','42000'),
	1140=>array('ER_MIX_OF_GROUP_FUNC_AND_FIELDS ','S1000 ','42000'),
	1141=>array('ER_NONEXISTING_GRANT ','S1000 ','42000'),
	1142=>array('ER_TABLEACCESS_DENIED_ERROR ','S1000 ','42000'),
	1143=>array('ER_COLUMNACCESS_DENIED_ERROR ','S1000 ','42000'),
	1144=>array('ER_ILLEGAL_GRANT_FOR_TABLE ','S1000 ','42000'),
	1145=>array('ER_GRANT_WRONG_HOST_OR_USER ','S1000 ','42000'),
	1146=>array('ER_NO_SUCH_TABLE ','S1000 ','42S02'),
	1147=>array('ER_NONEXISTING_TABLE_GRANT ','S1000 ','42000'),
	1148=>array('ER_NOT_ALLOWED_COMMAND ','S1000 ','42000'),
	1149=>array('ER_SYNTAX_ERROR ','S1000 ','42000'),
	1152=>array('ER_ABORTING_CONNECTION ','S1000 ','08S01'),
	1153=>array('ER_NET_PACKET_TOO_LARGE ','S1000 ','08S01'),
	1154=>array('ER_NET_READ_ERROR_FROM_PIPE ','S1000 ','08S01'),
	1155=>array('ER_NET_FCNTL_ERROR ','S1000 ','08S01'),
	1156=>array('ER_NET_PACKETS_OUT_OF_ORDER ','S1000 ','08S01'),
	1157=>array('ER_NET_UNCOMPRESS_ERROR ','S1000 ','08S01'),
	1158=>array('ER_NET_READ_ERROR ','S1000 ','08S01'),
	1159=>array('ER_NET_READ_INTERRUPTED ','S1000 ','08S01'),
	1160=>array('ER_NET_ERROR_ON_WRITE ','S1000 ','08S01'),
	1161=>array('ER_NET_WRITE_INTERRUPTED ','S1000 ','08S01'),
	1162=>array('ER_TOO_LONG_STRING ','S1000 ','42000'),
	1163=>array('ER_TABLE_CANT_HANDLE_BLOB ','S1000 ','42000'),
	1164=>array('ER_TABLE_CANT_HANDLE_AUTO_INCREMENT ','S1000 ','42000'),
	1166=>array('ER_WRONG_COLUMN_NAME ','S1000 ','42000'),
	1167=>array('ER_WRONG_KEY_COLUMN ','S1000 ','42000'),
	1169=>array('ER_DUP_UNIQUE ','S1000 ','23000'),
	1170=>array('ER_BLOB_KEY_WITHOUT_LENGTH ','S1000 ','42000'),
	1171=>array('ER_PRIMARY_CANT_HAVE_NULL ','S1000 ','42000'),
	1172=>array('ER_TOO_MANY_ROWS ','S1000 ','42000'),
	1173=>array('ER_REQUIRES_PRIMARY_KEY ','S1000 ','42000'),
	1177=>array('ER_CHECK_NO_SUCH_TABLE ','S1000 ','42000'),
	1178=>array('ER_CHECK_NOT_IMPLEMENTED ','S1000 ','42000'),
	1179=>array('ER_CANT_DO_THIS_DURING_AN_TRANSACTION ','S1000 ','25000'),
	1184=>array('ER_NEW_ABORTING_CONNECTION ','S1000 ','08S01'),
	1189=>array('ER_MASTER_NET_READ ','S1000 ','08S01'),
	1190=>array('ER_MASTER_NET_WRITE ','S1000 ','08S01'),
	1203=>array('ER_TOO_MANY_USER_CONNECTIONS ','S1000 ','42000'),
	1205=>array('ER_LOCK_WAIT_TIMEOUT ','41000 ','41000'),
	1207=>array('ER_READ_ONLY_TRANSACTION ','S1000 ','25000'),
	1211=>array('ER_NO_PERMISSION_TO_CREATE_USER ','S1000 ','42000'),
	1213=>array('ER_LOCK_DEADLOCK ','41000 ','40001'),
	1216=>array('ER_NO_REFERENCED_ROW ','S1000 ','23000'),
	1217=>array('ER_ROW_IS_REFERENCED ','S1000 ','23000'),
	1218=>array('ER_CONNECT_TO_MASTER ','S1000 ','08S01'),
	1222=>array('ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT ','S1000 ','21000'),
	1226=>array('ER_USER_LIMIT_REACHED ','S1000 ','42000'),
	1230=>array('ER_NO_DEFAULT ','S1000 ','42000'),
	1231=>array('ER_WRONG_VALUE_FOR_VAR ','S1000 ','42000'),
	1232=>array('ER_WRONG_TYPE_FOR_VAR ','S1000 ','42000'),
	1234=>array('ER_CANT_USE_OPTION_HERE ','S1000 ','42000'),
	1235=>array('ER_NOT_SUPPORTED_YET ','S1000 ','42000'),
	1239=>array('ER_WRONG_FK_DEF ','S1000 ','42000'),
	1241=>array('ER_OPERAND_COLUMNS ','S1000 ','21000'),
	1242=>array('ER_SUBQUERY_NO_1_ROW ','S1000 ','21000'),
	1247=>array('ER_ILLEGAL_REFERENCE ','S1000 ','42S22'),
	1248=>array('ER_DERIVED_MUST_HAVE_ALIAS ','S1000 ','42000'),
	1249=>array('ER_SELECT_REDUCED ','S1000 ','01000'),
	1250=>array('ER_TABLENAME_NOT_ALLOWED_HERE ','S1000 ','42000'),
	1251=>array('ER_NOT_SUPPORTED_AUTH_MODE ','S1000 ','08004'),
	1252=>array('ER_SPATIAL_CANT_HAVE_NULL ','S1000 ','42000'),
	1253=>array('ER_COLLATION_CHARSET_MISMATCH ','S1000 ','42000'),
	1261=>array('ER_WARN_TOO_FEW_RECORDS ','S1000 ','01000'),
	1262=>array('ER_WARN_TOO_MANY_RECORDS ','S1000 ','01000'),
	1263=>array('ER_WARN_NULL_TO_NOTNULL ','S1000 ','01000'),
	1264=>array('ER_WARN_DATA_OUT_OF_RANGE ','S1000 ','01000'),
	1265=>array('ER_WARN_DATA_TRUNCATED ','S1000 ','01000'),
	1280=>array('ER_WRONG_NAME_FOR_INDEX ','S1000 ','42000'),
	1281=>array('ER_WRONG_NAME_FOR_CATALOG ','S1000 ','42000'),
	1286=>array('ER_UNKNOWN_STORAGE_ENGINE ','S1000 ','42000'),
);

class DB {

	var $conn;
	var $iface;
	var $host;
	var $db;
	var $usr;
	var $pswd;
	var $link;
	var $system;

	function &DB ($options) {

		foreach ($options as $key => $val) { $this->$key = $val; }

		if ($this->iface == "mysql") {

			$this->link=mysql_connect(
					$this->host,
					$this->user,
					$this->password);
			mysql_select_db ($this->db);
		} elseif ($this->iface == "pg") {

			$this->link=pg_connect ("host=$this->host ".
					"user=$this->usr ".
					"password=$this->pswd ".
					"dbname=$this->db");
		}
	}

	function &query($sttmnt) {

		if ($this->iface == "mysql")

			return(mysql_query($sttmnt,$this->link));
		elseif ($this->iface == "pg")

			return(pg_query($this->link,$sttmnt));
	}

	function &fetch_row(&$handler) {

		if (!$handler) return(null);
		if ($this->iface == "mysql")

				return(mysql_fetch_array($handler));
		elseif ($this->iface == "pg")

				return(pg_fetch_array($handler));
	}

	function &fetch_object(&$handler) {

		if (!$handler) return(null);
		if ($this->iface == "mysql")

				return(mysql_fetch_object($handler));
		elseif ($this->iface == "pg")

				return(pg_fetch_object($handler));
	}

	function &fetch_array(&$handler, $type=MYSQL_BOTH) {

		if (!$handler) return(null);
		if ($this->iface == "mysql")

				return(mysql_fetch_array($handler, $type));
		elseif ($this->iface == "pg")

				return(pg_fetch_array($handler, $type));
	}

	function &affected_rows() {

		if ($this->iface == "mysql")

			return(mysql_affected_rows($this->link));
		elseif ($this->iface == "pg")

			return(pg_affected_rows($this->link));
	}

	function result($results, $row) {

		if ($this->iface == "mysql") return(mysql_result($results,$row));
		#elseif ($this->iface == "pg") return(pg_result($results,$row));
	}

	function insert_id() {

		if ($this->iface == "mysql") return(mysql_insert_id($this->link));
		elseif ($this->iface == "pg") return(pg_last_oid($this->link));
	}

	function num_rows(&$handler) {

		if ($this->iface == "mysql") return(mysql_num_rows($handler));
		elseif ($this->iface == "pg") return(pg_num_rows($handler));
	}

	function get_error ($error_id) {

		global $_MYSQL_ERROR;

		return isset ($_MYSQL_ERROR[$error_id]["msg"]) ?
				$_MYSQL_ERROR[$error_id]["msg"] :
				$_MYSQL_ERROR[$error_id][0];
	}
}

?>
